<template>
	<view class="content">
		<u-avatar src="/static/reCharge/wx.png" size="218rpx" class="avatar"></u-avatar>
		<text class="content_auth">微信授权</text>
		<text class="content_text">{{title}}</text>
		<view class="btn" @click="toAuthorize">点击进行微信授权</view>
	</view>
</template>

<script>
	import webUni from "@/common/uni.webview.1.5.2.js";
	export default {
		data() {
			return {
				title: '',
				urlParams: this.$store.state.urlParams,
			};
		},
		onLoad(options) {
			if (options.type == 1) {
				this.title = "绑定后您可使用微信进行提现"
			} else {
				this.title = "您下次可以使用新微信进行提现"
			}
			let that = this;
			window.LoginSuccess = function(data) { //授权成功
				// uni.$u.toast("进入登录成功回调")
				console.log("进入登录成功回调", data);
				// uni.$u.toast(JSON.stringify(data))
				// return
				setTimeout(() => {
					that.api.bindwx({
						...uni.getStorageSync("urlParams"),
						code: data.code
					}).then(res => {
						console.log(res);
						if (res.data.code == 200) {
							uni.navigateTo({
								url: '/pages/withdrawal/index'
							})
						}
					})
				}, 2000)
			}
		},
		methods: {
			//向app端发起微信授权
			toAuthorize() {
				// uni.$u.toast("向app端发起微信授权")
				webUni.postMessage({
					data: {
						type: "wxLogin",
						data: []
					},
				});
			},
		}
	};
</script>

<style lang="scss" scoped>
	.page {
		margin: 20rpx;
	}

	// ::v-deep .u-status-bar {
	// 	height: 80rpx !important;
	// }

	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 30px;
		box-sizing: border-box;

		.avatar {
			margin-top: 216rpx;
		}

		&_auth {
			font-family: Source Han Sans SC;
			font-weight: bold;
			font-size: 56rpx;
			color: #404040;
			margin-top: 22rpx;
			margin-bottom: 16rpx;
		}

		&_text {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #404040;
			margin-bottom: 56rpx;
		}

		.btn {
			width: 100%;
			color: #fff;
			padding: 23rpx 0rpx;
			background-color: #28ac3e;
			text-align: center;
			border-radius: 16rpx;
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 30rpx;
			color: #ffffff;
		}
	}
</style>